import {EventKey,StorageKey,OtherKey} from "../common_for_guosheng/Key";


import {
    GAMEMODEGS
} from './GameGSDefine';
export const GameGSData = {
    diamond: 10,
    bestLevel: 0,
    bestScore: 0,
    challengeData: null,

    gameMode: GAMEMODEGS.DEFAULT,

    init() {
        this.diamond = F.Data.getItem(StorageKey.DIAMOND);
        this.bestLevel = F.Data.getItem(StorageKey.BEST_LEVEL, 0);
        this.bestScore = F.Data.getItem(StorageKey.BEST_SCORE, 0);
        this.challengeData = F.Data.getItem(StorageKey.LAST_GAME);

        if (!this.diamond && this.diamond != 0) {
            this.diamond = 10;
        }
    },

    subScore(score) {
        F.GSPartner.setUserCloudStorage(OtherKey.kRecord, score);
    },

    getDiamond() {
        return this.diamond;
    },

    addDiamond(count) {
        this.diamond += count;
        F.Data.setItem(StorageKey.DIAMOND, this.diamond);
        F.OnEvent.fire(EventKey.EVENT_DIAMOND_CHANGE);
    },

    subDiamond(count) {
        if (this.diamond < count) {
            return false;
        }
        this.diamond -= count;
        F.Data.setItem(StorageKey.DIAMOND, this.diamond);
        F.OnEvent.fire(EventKey.EVENT_DIAMOND_CHANGE);
        return true;
    },

    getBestLevel() {
        return this.bestLevel;
    },
    getBestScore() {
        return this.bestScore;
    },
    setBestLevel(level) {
        if (this.bestLevel >= level) {
            return;
        }
        this.bestLevel = level;
        F.Data.setItem(StorageKey.BEST_LEVEL, this.bestLevel);
    },

    setBestScore(score) {
        if (this.bestScore >= score) {
            return;
        }
        this.bestScore = score;
        F.Data.setItem(StorageKey.BEST_SCORE, this.bestScore);
        this.subScore(this.bestScore);
    },

    getChallengeData() {
        return this.challengeData;
    },

    getGameMode() {
        return this.gameMode;
    },

    setGameMode(mode) {
        this.gameMode = mode;
    },

    saveLastGame(challengeData) {
        this.challengeData = challengeData;
        F.Data.setItem(StorageKey.LAST_GAME, challengeData);
    },

}